home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / PageMaker 6.5 SDK Mac / SourceCode / C_Language / ExportF / Common / Main.cpp < prev   
C/C++ Source or Header  |  1996-10-03  |  8KB  |  334 lines

  1. /*
  2.  *--- main.cpp ----------------------------------------------------------
  3.  * Copyright (c) 1992-96 Adobe Systems, Inc.  All rights reserved.
  4.  *
  5.  * PageMaker plug-in.
  6.  *-----------------------------------------------------------------------
  7.  */
  8.  
  9. /* ---------------- PageMaker SDK include files ---------------- */
  10. #include "PMPlugin.h"
  11. #include "CIObjectAccess.h"
  12.  
  13. /* ---------------- Plug-in include files ---------------- */
  14. #include "ExportF.h"
  15. #include "Convert.h"
  16.  
  17. #ifdef MACINTOSH
  18.     #include "WinTypes.h"
  19. #endif //MACINTOSH
  20.  
  21. /* ---------------- Cross-platform include files ---------------- */
  22. #include <string.h>
  23. #include <stdio.h>
  24.  
  25. /* ---------------- Platform specific include files ---------------- */
  26. #ifdef MACINTOSH
  27.     #include <types.h>
  28.     #ifndef powerc
  29.         #include <A4Stuff.h>
  30.         #include <SetUpA4.h>
  31.     #endif
  32. #else
  33.     #include <windows.h>
  34. #endif
  35.  
  36. /* ---------------- Type definitions ---------------- */
  37.  
  38. /* ---------------- Definitions ---------------- */
  39. #define SUCCESS    1
  40. #define FAILURE 0
  41. #define STAYINMEMORY -1
  42.  
  43. /* ---------------- PageMaker (New)SDK include files ---------------- */
  44. #include "CIInterfaceManager.h"
  45. #include "PMEvent.h"
  46. #include "CIBasic.h"
  47. #include "PMInterfaceIDs.h"
  48. #include "CICommandsAndQueries.h"
  49.  
  50. /* ---------------- Function declarations ---------------- */
  51. PMXErr DoInvoke( PMMessage *pMsg );
  52. PMXErr DoLoad(PMMessage* pMsg);
  53. PMXErr DoRegister(PMMessage* pMsg);
  54. PMXErr DoInvoke(PMMessage* pMsg);
  55. PMXErr DoEvent(PMMessage* pMsg);
  56. PMXErr DoSysEvent(PMMessage* pMsg);
  57. PMXErr DoAcquireInterface(PMMessage* pMsg);
  58. PMXErr DoReleaseInterface( PMMessage *pMsg );
  59. PMXErr DoUnload(PMMessage* pMsg);
  60. PMXErr DoShutdown(PMMessage* pMsg);
  61. PMXErr DoCleanup(PMMessage* pMsg);
  62.  
  63. #ifdef MACINTOSH
  64.     #ifdef powerc
  65.         #pragma export on
  66.     #endif
  67.         PMXErr main(PMMessage *pMsg);
  68.     #ifdef powerc
  69.         #pragma export off
  70.     #endif
  71. #else
  72.     BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved);
  73. #endif
  74.  
  75. #ifdef powerc
  76.     #pragma export on
  77. #endif
  78.     PMXErr    ConvertMeas(kUnits srcType, float srcSize, kUnits destType, char *destStr, 
  79.                     float *destSize, size_t *destStrLen, PMBool localise);
  80. #ifdef powerc
  81.     #pragma export off
  82. #endif
  83.  
  84. /* ---------------- Globals ---------------- */
  85. sPMParamBlockPtr thePB = NULL;
  86. CICommandQuery *pCmdQry = (CICommandQuery *)NULL;
  87. CIInterfaceManager    *gpIntfMgr;
  88. extern kUnits    gSrcType, gDestType;
  89. extern PMBool        gLocalise;
  90.  
  91. #ifdef WINDOWS
  92.     HINSTANCE ghDLL;
  93.  
  94.     BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved)
  95.     {
  96.         ghDLL = hDLL;
  97.     
  98.         return TRUE;
  99.     }
  100. #endif
  101.  
  102. /*
  103.  *--- main --------------------------------------------------------------------
  104.  *  Entry point for plug-in control tasks.
  105.  *-----------------------------------------------------------------------------
  106.  */ 
  107. PMXErr main(PMMessage *pMsg)
  108. {
  109.     PMXErr    result;
  110. #if __MWERKS__ && __MC68K__
  111.     long oldA4 = SetCurrentA4();
  112.     RememberA4();
  113. #endif
  114.  
  115.     gpIntfMgr = pMsg->pInterfaceMgr;
  116.     
  117.     switch ( pMsg->opCode ) {
  118.         case kPMLoad: 
  119.             result = DoLoad(pMsg);
  120.             break;
  121.  
  122.         case kPMRegister: 
  123.             result = DoRegister(pMsg);
  124.             break;
  125.             
  126.         case kPMInvoke: 
  127.             result = DoInvoke(pMsg);
  128.             break;
  129.  
  130.         case kPMEvent: 
  131.             result = DoEvent(pMsg);
  132.             break;
  133.             
  134.         case kPMSysEvent: 
  135.             result = DoSysEvent(pMsg);
  136.             break;
  137.             
  138.         case kPMAcquireInterface: 
  139.             result = DoAcquireInterface(pMsg);
  140.             break;
  141.             
  142.         case kPMReleaseInterface: 
  143.             result = DoReleaseInterface(pMsg);
  144.             break;
  145.             
  146.         case kPMUnload: 
  147.             result = DoUnload(pMsg);
  148.             break;
  149.  
  150.         case kPMShutdown: 
  151.             result = DoShutdown(pMsg);
  152.             break;
  153.             
  154.         case kPMCleanup: 
  155.             result = DoCleanup(pMsg);
  156.             break;
  157.             
  158.         default: 
  159.             result = 0;
  160.     }
  161.  
  162. #if __MWERKS__ && __MC68K__
  163.     SetA4(oldA4);
  164. #endif
  165.  
  166.     return result;
  167. }
  168.  
  169. /*
  170.  *--- DoRegister --------------------------------------------------------------
  171.  *  Called if Plug-in registers for Events or adds new interfaces to PM.
  172.  *-----------------------------------------------------------------------------
  173.  */ 
  174. PMXErr DoRegister( PMMessage *pMsg )
  175. {
  176.     PMXErr result = SUCCESS;
  177.     gpIntfMgr = pMsg->pInterfaceMgr;
  178.  
  179.     gpIntfMgr->AddPMInterface(PIConvertName);
  180.  
  181. /*
  182.     {
  183.         LPVOID theInterface;
  184.         gpIntfMgr->AcquirePMInterface(PIConvertName, &theInterface);
  185.         gpIntfMgr->ReleasePMInterface(PIConvertName, &theInterface);
  186.     }
  187. */
  188.     return result;
  189. }
  190.  
  191. /*
  192.  *--- DoAcquireInterface ------------------------------------------------------
  193.  *  Called when other plug-ins acquire the exported interface.
  194.  *-----------------------------------------------------------------------------
  195.  */ 
  196. PMXErr DoAcquireInterface( PMMessage *pMsg )
  197. {
  198.     PMXErr result = SUCCESS;
  199.     
  200.     PMInterface *pPMInterface = (PMInterface*)pMsg->pPMData;
  201.  
  202.     if (strcmp(pPMInterface->pInterfaceName, PIConvertName) == 0)
  203.         pPMInterface->pInterface = (LPVOID *)ConvertMeas;
  204.     else
  205.         return FAILURE;
  206.  
  207.  
  208.     return result;
  209. }
  210.  
  211. /*
  212.  *--- DoReleaseInterface ------------------------------------------------------
  213.  *  Called when other plug-ins release the acquired interface.
  214.  *-----------------------------------------------------------------------------
  215.  */ 
  216. PMXErr DoReleaseInterface( PMMessage *pMsg )
  217. {
  218.     PMXErr result = SUCCESS;
  219.             
  220.     return result;
  221. }
  222.  
  223. /*
  224.  *--- DoInvoke ----------------------------------------------------------------
  225.  *  
  226.  *-----------------------------------------------------------------------------
  227.  */ 
  228. PMXErr DoInvoke( PMMessage *pMsg )
  229. {
  230.     PMXErr result;
  231.         
  232.     return SUCCESS;
  233. }
  234.  
  235. /*
  236.  *--- DoLoad ------------------------------------------------------------------
  237.  *  
  238.  *-----------------------------------------------------------------------------
  239.  */ 
  240. PMXErr DoLoad(PMMessage* pMsg)
  241. {
  242. #pragma unused (pMsg)
  243.     return CQ_SUCCESS;
  244.  
  245. }
  246.  
  247. /*
  248.  *--- DoEvent -----------------------------------------------------------------
  249.  *  
  250.  *-----------------------------------------------------------------------------
  251.  */ 
  252. PMXErr DoEvent(PMMessage* pMsg)
  253. {
  254. #pragma unused (pMsg)
  255.     return CQ_SUCCESS;
  256. }
  257.  
  258. /*
  259.  *--- DoSysEvent --------------------------------------------------------------
  260.  *  
  261.  *-----------------------------------------------------------------------------
  262.  */ 
  263. PMXErr DoSysEvent(PMMessage* pMsg)
  264. {
  265. #pragma unused (pMsg)
  266.     return CQ_SUCCESS;
  267. }
  268.  
  269. /*
  270.  *--- DoUnload ----------------------------------------------------------------
  271.  *  
  272.  *-----------------------------------------------------------------------------
  273.  */ 
  274. PMXErr DoUnload(PMMessage* pMsg)
  275. {
  276. #pragma unused (pMsg)
  277.     return STAYINMEMORY; //we want to stay in memory
  278. }
  279.  
  280. /*
  281.  *--- DoShutdown --------------------------------------------------------------
  282.  *  
  283.  *-----------------------------------------------------------------------------
  284.  */ 
  285. PMXErr DoShutdown(PMMessage* pMsg)
  286. {
  287. #pragma unused (pMsg)
  288.     return CQ_SUCCESS;
  289. }
  290.  
  291. /*
  292.  *--- DoCleanup ---------------------------------------------------------------
  293.  *  
  294.  *-----------------------------------------------------------------------------
  295.  */ 
  296. PMXErr DoCleanup(PMMessage* pMsg)
  297. {
  298. #pragma unused (pMsg)
  299.     return CQ_SUCCESS;
  300. }
  301.  
  302. /*
  303.  *--- ConvertMeas -------------------------------------------------------------
  304.  *  Actual Interface exported by this plug-in.
  305.  *
  306.  *    In:
  307.  *        Source Unit Type
  308.  *        Source Value
  309.  *        Destination Unit Type
  310.  *        Boolean -- Localise the string? Comma instead of point for decimal sep.
  311.  *
  312.  *    Out:
  313.  *        Converted value as a string with unit type
  314.  *        Converted value as number
  315.  *        String lenght
  316.  *-----------------------------------------------------------------------------
  317.  */ 
  318. PMXErr ConvertMeas(kUnits srcType, float srcSize, kUnits destType, char *destStr, 
  319.                 float *destSize, size_t *destStrLen, PMBool localise)
  320. {
  321.     PMXErr    result = SUCCESS;
  322.  
  323.     if (!gpIntfMgr->AcquirePMInterface((unsigned long)PMIID_CMDQRY, (LPVOID *)&pCmdQry))
  324.         pCmdQry->Retrieve (&thePB);
  325.     else
  326.         return CQ_FAILURE;
  327.     
  328.     result = Convert(srcType, srcSize, destType, destStr, destSize, destStrLen, localise);
  329.     
  330.     gpIntfMgr->ReleasePMInterface((LPVOID *)pCmdQry);
  331.     
  332.     return result;
  333. }
  334.